//
//  NSTimeZone+Extension.m
//  RuiHeApp
//
//  Created by Yan Chen on 2025/7/9.
//

#import "NSTimeZone+Extension.h"

@implementation NSTimeZone (Extension)

+(NSString*)getCurrentTimeZone
{
    // 获取当前时区
    NSTimeZone *timeZone = [NSTimeZone localTimeZone];

    // 获取时区相对于 UTC 的秒偏移量
    NSInteger secondsFromGMT = [timeZone secondsFromGMT];

    // 计算小时偏移量
    NSInteger hours = secondsFromGMT / 3600;
    NSInteger minutes = (secondsFromGMT % 3600) / 60;

    // 格式化时区字符串（如 "UTC-08"）
    NSString *timeZoneString;
    if (hours == 0 && minutes == 0) {
        timeZoneString = @"UTC±00";
    } else {
        NSString *sign = (hours >= 0) ? @"+" : @"-";
        hours = labs(hours); // 取绝对值
        timeZoneString = [NSString stringWithFormat:@"UTC%@%02ld", sign, (long)hours];
        
        // 如果需要显示分钟（如 "UTC-08:30"），取消下面的注释
        // if (minutes != 0) {
        //     timeZoneString = [NSString stringWithFormat:@"%@:%02ld", timeZoneString, (long)minutes];
        // }
    }
    return timeZoneString;
}
@end
